package cqie.personal.frame.controller;


import cqie.personal.frame.bo.GetUserBO;
import cqie.personal.frame.entity.UserInfo;
import cqie.personal.frame.enums.Code;
import cqie.personal.frame.exception.ValidationFailException;
import cqie.personal.frame.service.impl.UserInfoServiceImpl;
import cqie.personal.frame.vo.PageVO;
import cqie.personal.frame.vo.ResultVO;
import cqie.personal.frame.vo.UserView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yeeeeee
 * @since 2021-09-01
 */
@RestController
@Api(tags = "用户信息模块")
@RequestMapping("/user-info")
public class UserInfoController {

    @Resource
    private UserInfoServiceImpl userInfoService;

    @ApiOperation("条件查询用户信息")
    @GetMapping("**/getUserInfo")
    public ResultVO getUserInfo(GetUserBO user) throws ValidationFailException {
        PageVO<List<UserView>> result = userInfoService.getAllUser(user);
        if(result!=null&&result.getRecordCount()!=0){
            return new ResultVO(result);
        }
        return new ResultVO(Code.NULL_DATA.getCode(),Code.NULL_DATA.getMessage());
    }

    @ApiOperation("条件查询用户信息")
    @GetMapping("**/getStudentInfo")
    public ResultVO getStudentInfo(GetUserBO user) throws ValidationFailException {
        user.setUserType(0);
        PageVO<List<UserView>> result = userInfoService.getAllUser(user);
        if(result!=null&&result.getRecordCount()!=0){
            return new ResultVO(result);
        }
        return new ResultVO(Code.NULL_DATA.getCode(),Code.NULL_DATA.getMessage());
    }

    @ApiOperation("Get all teacher")
    @GetMapping("**/getAllTeacher")
    public  ResultVO getAllTeacher() throws  ValidationFailException {
        GetUserBO user = new GetUserBO();
        user.setUserType(1);
        user.setPageMax(999);
        PageVO<List<UserView>> result = userInfoService.getAllUser(user);
        if(result!=null&&result.getRecordCount()!=0){
            return new ResultVO(result);
        }
        return new ResultVO(Code.NULL_DATA.getCode(),Code.NULL_DATA.getMessage());
    }
}

